package mh.modules.mh.service.impl;

import mh.common.utils.R;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import mh.common.utils.PageUtils;
import mh.common.utils.Query;

import mh.modules.mh.dao.WeatherDao;
import mh.modules.mh.entity.WeatherEntity;
import mh.modules.mh.service.WeatherService;


@Service("weatherService")
public class WeatherServiceImpl extends ServiceImpl<WeatherDao, WeatherEntity> implements WeatherService {
    @Autowired
    private WeatherService weatherService;
    @Autowired
    private WeatherDao weatherDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<WeatherEntity> page = this.page(
                new Query<WeatherEntity>().getPage(params),
                new QueryWrapper<WeatherEntity>().like(StringUtils.isNotBlank((String) params.get("key")),"record_date",params.get("key"))
        );

        return new PageUtils(page);
    }

    /**
     * sql获得当前日期往前推七天
     * @return
     */
    @Override
    public R getWeeklyTemperature() {
       List<WeatherEntity> map = weatherDao.getWeeklyTemperature();
//        System.out.println(map);
        return R.ok().put("data",map);
    }

}